import { reactive, ref } from 'vue'
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { getTableList } from '/@/api/common/api';

const newValue = ref([])
async function getList() {
  newValue.value = await getTableList()
}
getList()
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '编码',
    align: "center",
    sorter: true,
    width: '100px',
    dataIndex: 'locationCode'
  },
  {
    title: '名称',
    align: "center",
    sorter: true,
    dataIndex: 'locationName'
  },
  //  {
  //   title: '仓库id',
  //   align:"center",
  //   dataIndex: 'warehouseId'
  //  },
  {
    title: '容量控制',
    align: "center",
    dataIndex: 'capacityControl',
    width: '100px',
    customRender: ({ text }) => {
      return render.renderSwitch(text, [{ text: '是', value: '1' }, { text: '否', value: '0' }])
    },
  },
  {
    title: '最大容量',
    align: "center",
    width: '100px',
    dataIndex: 'maximumCapacity'
  },
  {
    title: '重量控制',
    align: "center",
    width: '100px',
    dataIndex: 'weightControl',
    customRender: ({ text }) => {
      return render.renderSwitch(text, [{ text: '是', value: '1' }, { text: '否', value: '0' }])
    },
  },
  {
    title: '最大重量',
    align: "center",
    width: '100px',
    dataIndex: 'maximumWeight'
  },
  {
    title: '库管员',
    align: "center",
    width: '100px',
    dataIndex: 'libraryKeeperId',
    customRender:({text}) =>{
      return newValue.value.records.filter(item => item.username == text)[0]?.realname
    },
  },
  {
    title: '是否单独存放',
    align: "center",
    dataIndex: 'isStoreSeparately',
    width: '120px',
    customRender: ({ text }) => {
      return render.renderSwitch(text, [{ text: '是', value: '1' }, { text: '否', value: '0' }])
    },
  },
  {
    title: '联系电话',
    align: "center",
    width: '120px',
    dataIndex: 'phone'
  },
  {
    title: '第三方编码',
    align: "center",
    width: '110px',
    dataIndex: 'thirdPartyCode'
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    field: 'locationCode',
    label: '编码',
    component: 'Input',
    colProps: { span: 12 },
  },
  {
    field: 'locationName',
    label: '名称',
    component: 'Input',
    colProps: { span: 12 },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '编码',
    field: 'locationCode',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入编码!' },
      ];
    },
  },
  {
    label: '名称',
    field: 'locationName',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入名称!' },
      ];
    },
  },
  {
    label: '仓库ID',
    field: 'warehouseId',
    component: 'Input',
    show: false
  },
  {
    label: '仓库名称',
    field: 'warehouseName',
    component: 'Input',
    slot: 'warehouseSlot',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请选择仓库名称!' },
      ];
    },
  },
  {
    label: '容量控制',
    field: 'capacityControl',
    defaultValue: 0,
    component: 'JSwitch',
    componentProps: {
      options: [1, 0]
    },
  },
  {
    label: '最大容量',
    field: 'maximumCapacity',
    component: 'InputNumber',
  },
  {
    label: '重量控制',
    field: 'weightControl',
    defaultValue: 0,
    component: 'JSwitch',
    componentProps: {
      options: [1, 0]
    },
  },
  {
    label: '最大重量',
    field: 'maximumWeight',
    component: 'InputNumber',
  },
  {
    label: '库管员',
    field: 'libraryKeeperId',
    component: 'JSelectUserByDept',
    componentProps: {
      labelKey: 'realname',
      showButton:false
    },
  },
  {
    label: '是否单独存放',
    field: 'isStoreSeparately',
    defaultValue: "0",
    component: 'JSwitch',
    componentProps: {
      options: [1, 0]
    },
  },
  {
    label: '联系电话',
    field: 'phone',
    component: 'Input',
    rules: rules.rule('phone', false),
  },
  {
    label: '第三方编码',
    field: 'thirdPartyCode',
    component: 'Input',
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
];



/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}